package com.yewen.http.controller;

import com.yewen.http.entity.LoginAccount;
import com.yewen.http.service.AccountService;
import org.apache.catalina.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/yewen/logout")
public class LogoutHandler {
    private static Logger logger = LoggerFactory.getLogger(LogoutHandler.class);
    @GetMapping
    public ModelAndView logout(HttpServletRequest request){
        ModelAndView view = new ModelAndView();
        view.setViewName("redirect:/yewen/pages/login");
        if (request.getSession()!=null){
            if (request.getSession().getAttribute("isLogin")!=null)
                request.getSession().removeAttribute("isLogin");
            else logger.error("[LogoutHandler][Session中无isLogin属性]");
        }else {
            logger.error("[LogoutHandler][找不到Session]");
        }
        return view;
    }
}
